#!/usr/bin/env ruby
# register user to elgg website by sending registration data 
# directly to actions/register.php 

require 'net/http'
#require 'net/https'

http = Net::HTTP.new('rsn', 80)
#http.use_ssl = false
path = '/pg/register'

# GET request -> so the host can set his cookies
resp, data = http.get(path, nil)
cookie = resp.response['set-cookie']

puts 'Message = ' + resp.message


## POST request -> logging in
#data = 'serwis=wp.pl&url=profil.html&tryLogin=1&countTest=1&logowaniessl=1&login_username=blah&login_password=blah'
#headers = {
#  'Cookie' => cookie,
#  'Referer' => 'http://rsn/pg/register',
#  'Content-Type' => 'application/x-www-form-urlencoded'
#}

#resp, data = http.post(path, data, headers)


# Output on the screen -> we should get either a 302 redirect (after a successful login) or an error page
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each {|key, val| puts key + ' = ' + val}
puts data
